package com.ibeeking.found.msg.rest.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ibeeking.found.common.config.secret.RsaConfig;
import com.ibeeking.found.common.constants.GlobalConstant;
import com.ibeeking.found.common.entity.DictDTO;
import com.ibeeking.found.common.enums.DefaultEnum;
import com.ibeeking.found.common.enums.DictTypeEnum;
import com.ibeeking.found.common.enums.PublishStatusEnum;
import com.ibeeking.found.common.enums.sms.SmsVendorEnum;
import com.ibeeking.found.common.utils.UserUtils;

import com.ibeeking.gmc.global.api.feign.GlobalDictFeignClient;
import com.ibeeking.found.msg.rest.service.ISmsConfigService;
import com.ibeeking.found.msg.service.common.bo.*;
import com.ibeeking.found.msg.service.common.dos.SmsConfigDO;
import com.ibeeking.found.msg.service.common.param.*;
import com.ibeeking.found.msg.service.common.query.SmsConfigQuery;
import com.ibeeking.found.msg.service.common.vo.*;
import com.ibeeking.found.msg.service.mapper.SmsConfigMapper;
import com.ibeeking.nematos.core.utils.SpringBeanUtil;
import com.ibeeking.nematos.exception.BusinessException;
import com.ibeeking.nematos.log.utils.LogUtils;
import com.ibeeking.nematos.utils.bean.BeanUtil;
import com.ibeeking.nematos.utils.cryptor.PasswordCryptor;
import com.ibeeking.nematos.utils.cryptor.SimplePasswordCryptor;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.encryption.EncryptUtils;
import com.ibeeking.nematos.utils.json.JsonUtils;
import com.ibeeking.nematos.utils.result.ResponseResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName SmsConfigServiceImpl
 * @Description
 * @Author ibeeking
 * @Date 2020-12-09 10:54
 **/
@Service
public class SmsConfigServiceImpl extends ServiceImpl<SmsConfigMapper, SmsConfigDO> implements ISmsConfigService {

    @Resource
    private SmsConfigMapper smsConfigMapper;

    @Resource
    private GlobalDictFeignClient globalDictFeignClient;

    @Resource
    private RsaConfig rsaConfig;

    @Override
    public List<SmsConfigVO> list(SmsConfigQuery query) {
        List<SmsConfigDO> smsConfigDOS = smsConfigMapper.selectList(new LambdaQueryWrapper<SmsConfigDO>()
                .eq(query.getId() != null, SmsConfigDO::getId, query.getId())
                .eq(StringUtils.isNotBlank(query.getName()), SmsConfigDO::getName, query.getName())
                .eq(query.getHaveDefault()!= null, SmsConfigDO::getHaveDefault, query.getHaveDefault())
                .eq(query.getPublishStatus() != null, SmsConfigDO::getPublishStatus, query.getPublishStatus())
                .orderByDesc(SmsConfigDO::getModifyTime)
        );

        List<SmsConfigVO> smslConfigVOs = JsonUtils.jsonToList(smsConfigDOS, SmsConfigVO.class);
        List<SmsConfigVO> smsConfigResultVOS = new ArrayList<>();
        if(Collections3.isNotEmpty(smslConfigVOs)){
            PasswordCryptor cryptor = new SimplePasswordCryptor();
            Map<String, String> smsVendorMap = getSmsVendorDictNames();
            smsConfigResultVOS = smslConfigVOs.stream().map(d-> {
                SmsConfigVO smsConfigVO = BeanUtil.convertBean(d, SmsConfigVO.class);
                String venderCode = smsConfigVO.getSmsVendorCode();
                String otherInfo = smsConfigVO.getOtherInfo();
                if(StringUtils.isNotEmpty(smsConfigVO.getOtherInfo())) {
                    if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_ALI.getCode())) {
                        SmsConfigByAliVO smsConfigByAliVO = JsonUtils.fromJson(otherInfo, SmsConfigByAliVO.class);
                        if(smsConfigByAliVO == null) smsConfigByAliVO= new SmsConfigByAliVO();
                        smsConfigByAliVO.setSmsVendorName(smsVendorMap.get(venderCode));
                        smsConfigVO.setSmsConfigByAli(smsConfigByAliVO);
                    }else if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_TECENT.getCode())) {
                        SmsConfigByTecentVO smsConfigByTecentVO = JsonUtils.fromJson(otherInfo, SmsConfigByTecentVO.class);
                        if(smsConfigByTecentVO == null) smsConfigByTecentVO= new SmsConfigByTecentVO();
                        smsConfigByTecentVO.setSmsVendorName(smsVendorMap.get(venderCode));
                        smsConfigVO.setSmsConfigByTecent(smsConfigByTecentVO);
                    }else if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_UCPASS.getCode())) {
                        SmsConfigByUcpassVO smsConfigByUcpassVO = JsonUtils.fromJson(otherInfo, SmsConfigByUcpassVO.class);
                        if(smsConfigByUcpassVO == null)  smsConfigByUcpassVO = new SmsConfigByUcpassVO();
                        smsConfigByUcpassVO.setSmsVendorName(smsVendorMap.get(venderCode));
                        smsConfigVO.setSmsConfigByUcpass(smsConfigByUcpassVO);
                    }else if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_SUBMAIL.getCode())) {
                        SmsConfigBySubmailVO smsConfigBySubmailVO = JsonUtils.fromJson(otherInfo, SmsConfigBySubmailVO.class);
                        if(smsConfigBySubmailVO == null)  smsConfigBySubmailVO = new SmsConfigBySubmailVO();
                        smsConfigBySubmailVO.setSmsVendorName(smsVendorMap.get(venderCode));
                        smsConfigVO.setSmsConfigBySubmail(smsConfigBySubmailVO);
                    }else if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_BAIDU.getCode())) {
                        SmsConfigByBaiduVO smsConfigByBaiduVO = JsonUtils.fromJson(otherInfo, SmsConfigByBaiduVO.class);
                        if(smsConfigByBaiduVO == null)  smsConfigByBaiduVO = new SmsConfigByBaiduVO();
                        smsConfigByBaiduVO.setSmsVendorName(smsVendorMap.get(venderCode));
                        smsConfigVO.setSmsConfigByBaidu(smsConfigByBaiduVO);
                    }

                }
                String encryptPassword = d.getUserPassword();
                if(StringUtils.isNotEmpty(encryptPassword)){
                    String password = cryptor.decrypt(encryptPassword);
                    smsConfigVO.setUserPassword(password);
                }
                smsConfigVO.setSmsVendorName(smsVendorMap.get(venderCode));
                smsConfigVO.setHaveDefaultDesc(DefaultEnum.getEnum(d.getHaveDefault()).getDesc());
                smsConfigVO.setPublishStatusDesc(PublishStatusEnum.getName(d.getPublishStatus()));
                return smsConfigVO;
            }).collect(Collectors.toList());
        }

        return smsConfigResultVOS;
    }

    @Override
    public List<SmsConfigVO> listAll() {
        SmsConfigQuery query = new SmsConfigQuery();
        return getBean().list(query);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean modify(SmsConfigParam param) {

        Long userId = UserUtils.getUserId();
        String vendorCode = param.getSmsVendorCode();
        SmsConfigDO smsConfigDO = BeanUtil.convertBean(param, SmsConfigDO.class);
        String password = param.getUserPassword();
        if(StringUtils.isNotEmpty(password)){
            PasswordCryptor cryptor = new SimplePasswordCryptor();
            String encryptPassword = cryptor.encrypt(password);
            smsConfigDO.setUserPassword(encryptPassword);
        }
        if(vendorCode.equalsIgnoreCase(SmsVendorEnum.SMS_ALI.getCode())) {
            SmsConfigByAliParam aliParam = param.getSmsConfigByAli();
            if(aliParam == null) aliParam = new SmsConfigByAliParam();
            aliParam.setConfigId(param.getId());
            aliParam.setSmsVendorCode(vendorCode);
            smsConfigDO.setOtherInfo(JsonUtils.toJsonStr(aliParam));
        }else if(vendorCode.equalsIgnoreCase(SmsVendorEnum.SMS_TECENT.getCode())) {
            SmsConfigByTecentParam tecentParam = param.getSmsConfigByTecent();
            if(tecentParam == null) tecentParam = new SmsConfigByTecentParam();
            tecentParam.setConfigId(param.getId());
            tecentParam.setSmsVendorCode(vendorCode);
            smsConfigDO.setOtherInfo(JsonUtils.toJsonStr(tecentParam));

        }else if(vendorCode.equalsIgnoreCase(SmsVendorEnum.SMS_UCPASS.getCode())) {
            SmsConfigByUcpassParam ucpassParam = param.getSmsConfigByUcpass();
            if(ucpassParam == null) ucpassParam = new SmsConfigByUcpassParam();
            ucpassParam.setConfigId(param.getId());
            ucpassParam.setSmsVendorCode(vendorCode);
            smsConfigDO.setOtherInfo(JsonUtils.toJsonStr(ucpassParam));
        }else if(vendorCode.equalsIgnoreCase(SmsVendorEnum.SMS_SUBMAIL.getCode())) {
            SmsConfigBySubmailParam submailParam = param.getSmsConfigBySubmail();
            if(submailParam == null) submailParam = new SmsConfigBySubmailParam();
            submailParam.setConfigId(param.getId());
            submailParam.setSmsVendorCode(vendorCode);
            smsConfigDO.setOtherInfo(JsonUtils.toJsonStr(submailParam));
        }else if(vendorCode.equalsIgnoreCase(SmsVendorEnum.SMS_BAIDU.getCode())) {
            SmsConfigByBaiduParam baiduParam = param.getSmsConfigByBaidu();
            if(baiduParam == null) baiduParam = new SmsConfigByBaiduParam();
            baiduParam.setConfigId(param.getId());
            baiduParam.setSmsVendorCode(vendorCode);
            smsConfigDO.setOtherInfo(JsonUtils.toJsonStr(baiduParam));
        }

        smsConfigDO.setModifyBy(userId);
        smsConfigDO.setModifyTime(LocalDateTime.now());
        return smsConfigMapper.updateById(smsConfigDO) > 0;
    }

    @Override
    public SmsConfigVO view(Long id) {
        SmsConfigDO smsConfigDO = smsConfigMapper.selectById(id);
        if(smsConfigDO == null){
            throw new BusinessException("没有找到相关记录");
        }
        SmsConfigVO smsConfigVO = BeanUtil.convertBean(smsConfigDO, SmsConfigVO.class);

        String otherInfo = smsConfigVO.getOtherInfo();
        Map<String, String> smsVendorMap = getSmsVendorDictNames();
        if(StringUtils.isNotEmpty(otherInfo)) {

            String venderCode = smsConfigVO.getSmsVendorCode();
            if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_ALI.getCode())) {
                SmsConfigByAliVO smsConfigByAliVO = JsonUtils.fromJson(otherInfo, SmsConfigByAliVO.class);
                if(smsConfigByAliVO == null) smsConfigByAliVO= new SmsConfigByAliVO();
                smsConfigByAliVO.setSmsVendorName(smsVendorMap.get(venderCode));
                smsConfigVO.setSmsConfigByAli(smsConfigByAliVO);
            }else if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_TECENT.getCode())) {
                SmsConfigByTecentVO smsConfigByTecentVO = JsonUtils.fromJson(otherInfo, SmsConfigByTecentVO.class);
                if(smsConfigByTecentVO == null) smsConfigByTecentVO= new SmsConfigByTecentVO();
                smsConfigByTecentVO.setSmsVendorName(smsVendorMap.get(venderCode));
                smsConfigVO.setSmsConfigByTecent(smsConfigByTecentVO);
            }else if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_UCPASS.getCode())) {
                SmsConfigByUcpassVO smsConfigByUcpassVO = JsonUtils.fromJson(otherInfo, SmsConfigByUcpassVO.class);
                if(smsConfigByUcpassVO == null)  smsConfigByUcpassVO = new SmsConfigByUcpassVO();
                smsConfigByUcpassVO.setSmsVendorName(smsVendorMap.get(venderCode));
                smsConfigVO.setSmsConfigByUcpass(smsConfigByUcpassVO);
            }else if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_SUBMAIL.getCode())) {
                SmsConfigBySubmailVO smsConfigBySubmailVO = JsonUtils.fromJson(otherInfo, SmsConfigBySubmailVO.class);
                if(smsConfigBySubmailVO == null)  smsConfigBySubmailVO = new SmsConfigBySubmailVO();
                smsConfigBySubmailVO.setSmsVendorName(smsVendorMap.get(venderCode));
                smsConfigVO.setSmsConfigBySubmail(smsConfigBySubmailVO);
            }else if(venderCode.equalsIgnoreCase(SmsVendorEnum.SMS_BAIDU.getCode())) {
                SmsConfigByBaiduVO smsConfigByBaiduVO = JsonUtils.fromJson(otherInfo, SmsConfigByBaiduVO.class);
                if(smsConfigByBaiduVO == null)  smsConfigByBaiduVO = new SmsConfigByBaiduVO();
                smsConfigByBaiduVO.setSmsVendorName(smsVendorMap.get(venderCode));
                smsConfigVO.setSmsConfigByBaidu(smsConfigByBaiduVO);
            }

        }
        String encryptPassword = smsConfigVO.getUserPassword();
        if(StringUtils.isNotEmpty(encryptPassword)){
            PasswordCryptor cryptor = new SimplePasswordCryptor();
            String password = cryptor.decrypt(encryptPassword);
            smsConfigVO.setUserPassword(password);
        }
        smsConfigVO.setHaveDefaultDesc(DefaultEnum.getEnum(smsConfigVO.getHaveDefault()).getDesc());
        smsConfigVO.setPublishStatusDesc(PublishStatusEnum.getName(smsConfigVO.getPublishStatus()));

        return smsConfigVO;
    }

    @Override
    public SmsConfigBO queryDefaultConfig() {
        List<SmsConfigDO> smsConfigDOS = smsConfigMapper.selectList(new LambdaQueryWrapper<SmsConfigDO>().eq(SmsConfigDO::getHaveDefault, DefaultEnum.YES.getValue()));
        if(Collections3.isEmpty(smsConfigDOS)){
            throw new BusinessException("没有缺省配置");
        }

        SmsConfigBO smsConfigBO = BeanUtil.convertBean(smsConfigDOS.get(0), SmsConfigBO.class);
        String otherInfo = smsConfigBO.getOtherInfo();
        if(StringUtils.isNotEmpty(otherInfo)) {
            if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_ALI.getCode())) {
                SmsConfigByAliBO smsConfigByAliBO = JsonUtils.fromJson(otherInfo, SmsConfigByAliBO.class);
                if(smsConfigByAliBO == null) smsConfigByAliBO = new SmsConfigByAliBO();
                smsConfigBO.setSmsConfigByAli(smsConfigByAliBO);
            }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_TECENT.getCode())) {
                SmsConfigByTecentBO smsConfigByTecentBO = JsonUtils.fromJson(otherInfo, SmsConfigByTecentBO.class);
                if(smsConfigByTecentBO == null) smsConfigByTecentBO = new SmsConfigByTecentBO();
                smsConfigBO.setSmsConfigByTecent(smsConfigByTecentBO);
            }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_UCPASS.getCode())) {
                SmsConfigByUcpassBO smsConfigByUcpassBO = JsonUtils.fromJson(otherInfo, SmsConfigByUcpassBO.class);
                if(smsConfigByUcpassBO == null)  smsConfigByUcpassBO = new SmsConfigByUcpassBO();
                smsConfigBO.setSmsConfigByUcpass(smsConfigByUcpassBO);
            }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_SUBMAIL.getCode())) {
                SmsConfigBySubmailBO smsConfigBySubmailBO = JsonUtils.fromJson(otherInfo, SmsConfigBySubmailBO.class);
                if(smsConfigBySubmailBO == null)  smsConfigBySubmailBO = new SmsConfigBySubmailBO();
                smsConfigBO.setSmsConfigBySubmail(smsConfigBySubmailBO);
            }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_BAIDU.getCode())) {
                SmsConfigByBaiduBO smsConfigByBaiduBO = JsonUtils.fromJson(otherInfo, SmsConfigByBaiduBO.class);
                if(smsConfigByBaiduBO == null)  smsConfigByBaiduBO = new SmsConfigByBaiduBO();
                smsConfigBO.setSmsConfigByBaidu(smsConfigByBaiduBO);
            }

        }
        return smsConfigBO;
    }

    @Override
    public SmsConfigBO queryById(Long id) {
        SmsConfigDO smsConfigDO = smsConfigMapper.selectById(id);
        if(smsConfigDO == null){
            throw new BusinessException("没有找到相关记录");
        }
        SmsConfigBO smsConfigBO = BeanUtil.convertBean(smsConfigDO, SmsConfigBO.class);
        String otherInfo = smsConfigBO.getOtherInfo();
        if(StringUtils.isNotEmpty(otherInfo)) {
            if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_ALI.getCode())) {
                SmsConfigByAliBO smsConfigByAliBO = JsonUtils.fromJson(otherInfo, SmsConfigByAliBO.class);
                if(smsConfigByAliBO == null) smsConfigByAliBO = new SmsConfigByAliBO();
                smsConfigBO.setSmsConfigByAli(smsConfigByAliBO);
            }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_TECENT.getCode())) {
                SmsConfigByTecentBO smsConfigByTecentBO = JsonUtils.fromJson(otherInfo, SmsConfigByTecentBO.class);
                if(smsConfigByTecentBO == null) smsConfigByTecentBO = new SmsConfigByTecentBO();
                smsConfigBO.setSmsConfigByTecent(smsConfigByTecentBO);
            }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_UCPASS.getCode())) {
                SmsConfigByUcpassBO smsConfigByUcpassBO = JsonUtils.fromJson(otherInfo, SmsConfigByUcpassBO.class);
                if(smsConfigByUcpassBO == null)  smsConfigByUcpassBO = new SmsConfigByUcpassBO();
                smsConfigBO.setSmsConfigByUcpass(smsConfigByUcpassBO);
            }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_SUBMAIL.getCode())) {
                SmsConfigBySubmailBO smsConfigBySubmailBO = JsonUtils.fromJson(otherInfo, SmsConfigBySubmailBO.class);
                if(smsConfigBySubmailBO == null)  smsConfigBySubmailBO = new SmsConfigBySubmailBO();
                smsConfigBO.setSmsConfigBySubmail(smsConfigBySubmailBO);
            }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_BAIDU.getCode())) {
                SmsConfigByBaiduBO smsConfigByBaiduBO = JsonUtils.fromJson(otherInfo, SmsConfigByBaiduBO.class);
                if(smsConfigByBaiduBO == null)  smsConfigByBaiduBO = new SmsConfigByBaiduBO();
                smsConfigBO.setSmsConfigByBaidu(smsConfigByBaiduBO);
            }
        }
        return smsConfigBO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean changePublishStatus(Long id, Integer status) {
        Long userId = UserUtils.getUserId();

        SmsConfigDO smsConfigDO = smsConfigMapper.selectById(id);
        if(smsConfigDO == null){
            throw new BusinessException("没有找到相关记录");
        }
        smsConfigDO.setPublishStatus(status);
        smsConfigDO.setModifyBy(userId);
        smsConfigDO.setModifyTime(LocalDateTime.now());
        return smsConfigMapper.updateById(smsConfigDO) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean changeDefaultStatus(Long id, Integer status) {
        Long userId = UserUtils.getUserId();

        if(status == DefaultEnum.YES.getValue()) {
            List<SmsConfigDO> otherSmsConfigDOS = smsConfigMapper.querySmsConfigByDefaultStatus(status);
            if(Collections3.isNotEmpty(otherSmsConfigDOS)){
                SmsConfigDO otherSmsConfigDO = otherSmsConfigDOS.get(0);
                if(otherSmsConfigDO.getId() != id){
                    otherSmsConfigDO.setHaveDefault(DefaultEnum.NO.getValue());
                    otherSmsConfigDO.setModifyBy(userId);
                    otherSmsConfigDO.setModifyTime(LocalDateTime.now());
                    smsConfigMapper.updateById(otherSmsConfigDO);
                }
            }
        }
        SmsConfigDO smsConfigDO = smsConfigMapper.selectById(id);
        if(smsConfigDO == null){
            throw new BusinessException("没有找到相关记录");
        }
        smsConfigDO.setHaveDefault(status);
        smsConfigDO.setPublishStatus(PublishStatusEnum.ENABLE.getValue());
        smsConfigDO.setModifyBy(userId);
        smsConfigDO.setModifyTime(LocalDateTime.now());
        return smsConfigMapper.updateById(smsConfigDO) > 0;
    }

    @Override
    public List<SmsConfigBO> queryEffectiveList() {
        List<SmsConfigDO> smsConfigDOS = smsConfigMapper.selectList(new LambdaQueryWrapper<>(SmsConfigDO.class)
                .eq(SmsConfigDO::getPublishStatus, PublishStatusEnum.ENABLE.getValue()));

        List<SmsConfigBO> smslConfigBOS= JsonUtils.jsonToList(smsConfigDOS, SmsConfigBO.class);
        List<SmsConfigBO> smsConfigResultBOS = new ArrayList<>();
        if(Collections3.isNotEmpty(smslConfigBOS)){
            smsConfigResultBOS = smslConfigBOS.stream().map(d-> {
                SmsConfigBO smsConfigBO = BeanUtil.convertBean(d, SmsConfigBO.class);
                String otherInfo = smsConfigBO.getOtherInfo();
                if(StringUtils.isNotEmpty(otherInfo)) {
                    if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_ALI.getCode())) {
                        SmsConfigByAliBO smsConfigByAliBO = JsonUtils.fromJson(otherInfo, SmsConfigByAliBO.class);
                        if(smsConfigByAliBO == null) smsConfigByAliBO = new SmsConfigByAliBO();
                        smsConfigBO.setSmsConfigByAli(smsConfigByAliBO);
                    }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_TECENT.getCode())) {
                        SmsConfigByTecentBO smsConfigByTecentBO = JsonUtils.fromJson(otherInfo, SmsConfigByTecentBO.class);
                        if(smsConfigByTecentBO == null) smsConfigByTecentBO = new SmsConfigByTecentBO();
                        smsConfigBO.setSmsConfigByTecent(smsConfigByTecentBO);
                    }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_UCPASS.getCode())) {
                        SmsConfigByUcpassBO smsConfigByUcpassBO = JsonUtils.fromJson(otherInfo, SmsConfigByUcpassBO.class);
                        if(smsConfigByUcpassBO == null)  smsConfigByUcpassBO = new SmsConfigByUcpassBO();
                        smsConfigBO.setSmsConfigByUcpass(smsConfigByUcpassBO);
                    }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_SUBMAIL.getCode())) {
                        SmsConfigBySubmailBO smsConfigBySubmailBO = JsonUtils.fromJson(otherInfo, SmsConfigBySubmailBO.class);
                        if(smsConfigBySubmailBO == null)  smsConfigBySubmailBO = new SmsConfigBySubmailBO();
                        smsConfigBO.setSmsConfigBySubmail(smsConfigBySubmailBO);
                    }else if(smsConfigBO.getSmsVendorCode().equalsIgnoreCase(SmsVendorEnum.SMS_BAIDU.getCode())) {
                        SmsConfigByBaiduBO smsConfigByBaiduBO = JsonUtils.fromJson(otherInfo, SmsConfigByBaiduBO.class);
                        if(smsConfigByBaiduBO == null)  smsConfigByBaiduBO = new SmsConfigByBaiduBO();
                        smsConfigBO.setSmsConfigByBaidu(smsConfigByBaiduBO);
                    }
                }
                return smsConfigBO;
            }).collect(Collectors.toList());
        }
        return smsConfigResultBOS;
    }

    private Map<String, String> getSmsVendorDictNames() {
        ResponseResult<List<DictDTO>> responseResult =  globalDictFeignClient.queryDictByType(DictTypeEnum.MSG_SMS_VENDOR.getValue());
        if (responseResult == null) return Collections3.emptyMap();
        List<DictDTO> dictDTOS =  responseResult.getData();
        if (Collections3.isEmpty(dictDTOS)) return Collections3.emptyMap();
        Map<String, String> dictDTOSMaps =   dictDTOS.stream().collect(Collectors.toMap(DictDTO::getValue, DictDTO::getLabel, (key1, key2) -> key2));

        return dictDTOSMaps;
    }

    private SmsConfigServiceImpl getBean() {
        return SpringBeanUtil.getBean(this.getClass());
    }

}
